/*
 * Created on 2006-2-23
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package cn.com.sbell.vss.csg.vap;

import javax.servlet.http.HttpServletRequest;

import cn.com.sbell.vss.ICommander;
import cn.com.sbell.vss.Response;
import cn.com.sbell.vss.csg.vap.bean.AlarmMessage;
import cn.com.sbell.vss.csg.vsclient.util.AlarmDispatchGroup;
import cn.com.sbell.vss.csg.vsclient.util.PropertiesHolder;

/**
 * @author liang.a.chen
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class AlarmListener implements ICommander{
			
//	private final static Log logger = LogFactory.getLog(AlarmListener.class);
	
	public Response execute(HttpServletRequest request) {
		PropertiesHolder holder = PropertiesHolder.getInstanceFromRequest(request);
		
		AlarmMessage alarmMsg = new AlarmMessage();
		alarmMsg.setAlarmType(holder.getStrProperty("alarmType"));
		alarmMsg.setCameraNumber(holder.getIntProperty("cameraNumber"));
		alarmMsg.setChannelNumber(holder.getIntProperty("channelNumber"));
		alarmMsg.setDiskNumber(holder.getIntProperty("diskNumber"));
		alarmMsg.setData(holder.getStrProperty("data"));
		alarmMsg.setServerIp(request.getRemoteAddr());
		if(alarmMsg.getCameraNumber() != null){
			alarmMsg.setServerType("CAM");
		}else{
			alarmMsg.setServerType("VS");
		}
		
		AlarmDispatchGroup.getAlarmDispatchGroup().addMessage(alarmMsg);
		
		Response response = Response.createResponse(request);
		response.setParameters(null);
	
		return response;
	}
}
